package main

import (
	"distributed/conf"
	"distributed/server"
	"fmt"
	"net/http"
	"net/rpc"
)

// todo: 考虑清楚，到底哪一方是 client
// todo: 需要完成 数据解析部分
func init() {
	conf.LoadConfig()
	server.ConnectStorage()
	server.Seed()
	server.Scheduler()
}

func main() {
	// todo: rpc-server -> worker
	// todo: rpc-client -> storage
	if err := rpc.Register(&server.Worker{}); err != nil {
		panic(err)
	}
	rpc.HandleHTTP()
	fmt.Printf("[ rpc server running in %v ]\n", conf.GetConfig("server_port"))
	if err := http.ListenAndServe(conf.GetConfig("server_port"), nil); err != nil {
		panic(err)
	}

	//http.HandleFunc("/register/function", )
}
